from datetime import datetime,timedelta
import os, string, sys, time, re, math, fileinput, glob, shutil
from model.FileInf import FileInf
from mmap import mmap, ACCESS_WRITE 
from io import BytesIO

class FileBlockWriter:

    # 创建文件
    def make(self,file):
        dir = os.path.dirname(file.pathSvr)
        # 创建目录
        if os.path.exists(dir)==False:
            os.makedirs(dir)

        if os.path.exists(file.pathSvr)==False:
            with open(file.pathSvr,'wb+') as f:
                f.truncate(file.lenLoc)
    
    # 写入块数据
    def write(self,fs,buffer):
        with open(fs.pathSvr,'rb+') as f:
            f.seek(fs.blockOffset,0)
            f.write(buffer.read())